/**
 * @author Leong Wai Lun A0032831R
 * @author Mohamed Ali Mohamed Hassan Sulaiman A0080050Y
 */

package jobadvertisement;

import java.io.*;

import properties.PropertiesDAO;
/**
 * 
 * read data from file,
 * write data to jobadvertisement file ,
 * delete  jobadvertisement file
 *
 */
public class JobAdvertisementDAO extends PropertiesDAO {
	public JobAdvertisementDAO() {
	}
	/**
	 * reads all the data stored in the jobadvertisement file
	 * @return boolean
	 */
	public boolean readDTOs() {
		return super.readDTOs(DTOTYPES.JOBADVERTISEMENT);
	}
	/**
	 * writes all the data into the jobadvertisement file.
	 * @return boolean
	 */
	public boolean writeDTOs() {
		return super.writeDTOs(DTOTYPES.JOBADVERTISEMENT);
	}
	/**
	 * returns the specified data according the input id
	 * @param id the id of data
	 * @return the specified data according the input id
	 */
    @Override
	public JobAdvertisementDTO getDTO(String id) {
		return (JobAdvertisementDTO) super.getDTO(id);
	}
    
    /*public ArrayList<JobAdvertisementDTO> getDTOs(String customerID) {
    	readDTOs();
    	
		//return (JobAdvertisementDTO) super.getDTO(id);
	}*/
	/**
	 * delete the jobadvertisement file by the input id
	 * @param id the id of data
	 * @return boolean
	 */  
        public boolean deleteJobAds(String id) {
            boolean jobDeleted = false;
            System.out.println("delete jobs called");

            this.readDTOs();
            JobAdvertisementDTO jaDTO = getDTO(id);
            if(jaDTO != null)
            {
                super.removeDTO(id);
                //edited by Zhang Na
                String dtoFilePath = System.getProperty("user.dir") + "/data/" + DTOTYPES.JOBADVERTISEMENT.toString() + "/" + jaDTO.getId();             
                try
                {
                    File dtoFile = new File(dtoFilePath);
                    dtoFile.exists();
                    dtoFile.delete();	
                }
                catch( Exception e )
                {
                	System.out.println(e.getMessage());
                }
                jobDeleted = true;
            }            
            return jobDeleted;
        }
        

}